import 'package:flutter/material.dart';
import 'package:lib_uikit/lib_uikit.dart';
import 'package:lib_uikit/theme/gt_colors_v3.dart';
import 'package:lib_uikit/widgets/bottomsheet/gt_bottom_sheet_v3.dart';

import '../text/gt_text.dart';

/// @Title   弹出标题内容文字列表bottomsheet
/// @Author: bryce
/// @CreateDate: 2023年10月18日16:09:54
Future<int?> showActionSheetV3(
  context, {
  required List<GTTitleContentModelV3> titleContentList,
  int selectedIndex = -1,
  double? maxHeight, // bottomSheet最大高度
  double? minHeight, // bottomSheet最小高度
  bool showBottomCancel = true, // 是否展示底部取消按钮
  bool showTopRightClose = false, // 是否展示右上角关闭按钮
  String? title,
  ValueChanged<int>? onItemClick,
  bool? isShowCheck = true,
  double? backgroundOpacity,
  VoidCallback? dismissCallBack,
}) async {
  return showGTBottomSheetV3(context,
      maxHeight: maxHeight,
      minHeight: minHeight,
      showBottomCancel: showBottomCancel,
      showTopRightClose: showTopRightClose,
      title: title,
      backgroundOpacity: backgroundOpacity,
      dismissCallBack: dismissCallBack,
      child: MediaQuery.removePadding(
          context: context,
          removeTop: true,
          removeBottom: true,
          child: ListView.separated(
            shrinkWrap: true,
            physics: const BouncingScrollPhysics(),
            itemCount: titleContentList.length,
            separatorBuilder: (BuildContext context, int index) => const SizedBox(height: 8),
            itemBuilder: (BuildContext context, int index) {
              bool isSelected = index == selectedIndex;
              if (!isShowCheck!) {
                isSelected = true;
              }
              GTTitleContentModelV3 item = titleContentList[index];
              return GestureDetector(
                onTap: () {
                  Navigator.pop(context, index);
                  onItemClick?.call(index);
                },
                behavior: HitTestBehavior.opaque,
                child: Container(
                  decoration: BoxDecoration(
                      color: isSelected ? GTColorsV3.neutral2.color : Colors.transparent,
                      borderRadius: BorderRadius.circular(6)),
                  padding: const EdgeInsets.all(12),
                  child: Row(
                    crossAxisAlignment:
                        (item.content ?? "").isNotEmpty ? CrossAxisAlignment.start : CrossAxisAlignment.center,
                    children: [
                      if (item.icon != null) ...[
                        Icon(
                          item.icon,
                          color: GTColorsV3.icon1.color,
                          size: 24,
                        ),
                        const SizedBox(
                          width: 8,
                        ),
                      ],
                      Expanded(
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            TextUtils.isEmpty(item.title)
                                ? Container()
                                : GTText(item.title!,
                                    style: gtTextStyleW500(fontSize: 14, color: GTColorsV3.text1.color)),
                            SizedBox(height: TextUtils.isNotEmpty(item.content) ? 4 : 0),
                            TextUtils.isEmpty(item.content)
                                ? Container()
                                : GTText(item.content!,
                                    style: gtTextStyleW400(fontSize: 11, color: GTColorsV3.text3.color)),
                          ],
                        ),
                      ),
                      Visibility(
                          visible: isSelected && isShowCheck!,
                          child: Column(
                            children: [
                              const SizedBox(
                                width: 12,
                              ),
                              Icon(
                                GTIconFont.e942,
                                color: GTColorsV3.icon9.color,
                                size: 16,
                              ),
                            ],
                          )),
                    ],
                  ),
                ),
              );
            },
          )));
}

class GTTitleContentModelV3 {
  final String? title;
  final String? content;
  final IconData? icon;

  GTTitleContentModelV3({this.title, this.content, this.icon});
}
